home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
docs
/
fpgawkii
/
parity.pds
< prev
next >
Wrap
Text File
|
1994-10-05
|
7KB
|
169 lines
;---------------------------------------------------------
; This PLDASM file demonstrates hierarchical design and
; the definition of modules using a parity detector
; example.
;---------------------------------------------------------
TITLE parity detector
;*-- beginning of 2-bit parity detector module -----------
; Our first module: a 2-bit parity detector (that's an
; XOR gate, guys). The DEFMOD keyword starts the module
; definition. This is followed by the name of the module
; (par2) and a parenthesized list of inputs and outputs.
;---------------------------------------------------------
DEFMOD par2 ( b[0:1], odd )
;---------------------------------------------------------
; Next comes the CHIP keyword, but for modules you don't
; want to specify a particular chip type. Instead, use
; "Intel_arch" as a kind of generic type of chip.
;---------------------------------------------------------
CHIP par2 Intel_arch
;---------------------------------------------------------
; Descriptions of the module inputs and outputs come next.
; You use the PIN statement, but DON'T ASSIGN PIN NUMBERS!
; That's because you are just defining the module right
; now and it has no specific location in the chip. The
; binding of our inputs and outputs to the physical pins
; only occurs later when this module is instantiated.
;---------------------------------------------------------
PIN b[0:1] ;* this is the 2-bit binary number
PIN odd ;* output is high if the parity is odd
EQUATIONS
odd = b0 :+: b1 ;* just an XOR gate!
;---------------------------------------------------------
; The ENDMOD keyword ends the definition of the 2-bit
; parity detector module.
;---------------------------------------------------------
ENDMOD
;*-- end of 2-bit parity detector module -----------------
;*-- beginning of 4-bit parity detector module -----------
; Now start defining the 4-bit parity detector module.
; This module uses two of the 2-bit parity detector
; modules to do its job.
;---------------------------------------------------------
DEFMOD par4( b[0:3], odd )
CHIP par4 Intel_arch
PIN b[0:3] ;* 4-bit binary input for parity check
PIN odd ;* odd is 1 if the 4-bit input is odd par.
; The following pins act like temporary variables.
PIN n[0:1] ;* these two pins are used to hold the
;* parity of the lower and upper 2-bit
;* fields, respectively.
;---------------------------------------------------------
; Here is where the 2-bit parity detectors are used.
; These calls to the 2-bit detectors must come AFTER the
; inputs and outputs for the current module are declared
; because you are going to hook these I/O pins to the I/O
; of the 2-bit detector sub-modules. The MODULE keyword
; indicates that you are going to use a sub-module.
; This keyword is followed by the name of the sub-module
; you want to use. This is followed by a parenthesized
; list that shows how I/O pins for the sub-module are
; hooked to the I/O pins of the current module.
;---------------------------------------------------------
; This sub-module receives the least significant 2 bits of
; the 4-bit input and stores their parity on the n0 pin.
MODULE par2( b[0:1]=b[0:1], odd=n0 )
; This sub-module receives the most significant 2 bits of
; the 4-bit input and stores their parity on the n1 pin.
MODULE par2( b[0:1]=b[2:3], odd=n1 )
; This last sub-module takes the output of the previous
; sub-modules and XORs them to generate the parity for
; the entire 4-bit word. You can use the par2
; module for this since it's just an XOR gate anyway.
MODULE par2( b0=n0, b1=n1, odd=odd )
ENDMOD
;*-- end of the 4-bit parity detector module -------------
;*-- beginning of 8-bit parity detector module -----------
; Now an 8-bit parity detector is built from two 4-bit
; parity detectors.
;---------------------------------------------------------
DEFMOD par8( b[0:7], odd )
CHIP par8 Intel_arch
PIN b[0:7] ;* 8 bits of data to check parity on
PIN odd ;* the parity output -- high if odd parity
PIN n[0:1] ;* pins for holding the parity of the
;* upper and lower 4-bit sections
; compute parity of lower 4 bits
MODULE par4( b[0:3]=b[0:3], odd=n0 )
; compute parity of upper 4 bits
MODULE par4( b[0:3]=b[4:7], odd=n1 )
; combine the upper and lower parities
MODULE par2( b0=n0, b1=n1, odd=odd )
ENDMOD
;*-- end of 8-bit parity detector module -----------------
;*---------------------------------------------------------
;* Call the 8-bit parity detector module and hook it to
;* the actual inputs and outputs of the FPGA.
;*---------------------------------------------------------
CHIP parity NFX780_84 ; use the FPGA now!!
PIN [47:51] in[0:4] ; parity detector inputs
PIN [77:78] in[5:6] ; parity detector inputs
PIN 34 odd_parity ; parity detector output
; Now call the 8-bit parity detector but only use
; seven bits of it. Set the most-significant bit to 0.
MODULE par8( b[0:6]=in[0:6], b7=GND, odd=odd_parity )
;---------------------------------------------------------
; Now do a simulation to make sure everything is OK. You
; really don't want to type in all 128 possible inputs,
; so you can just let the simulator handle it
; as you'll see below.
;---------------------------------------------------------
SIMULATION
; First, define a VECTOR called "number" from the 7
; input bits. Start with a [ and then list the
; inputs you want in the vector (most significant
; first, least significant last) after which you end
; the declaration with a ]. Don't forget the
; commas between the entries in the vector list!
VECTOR number := [in6,in5,in4,in3,in2,in1,in0]
TRACE_ON number odd_parity
; Now, you can iterate through all 127 input
; combinations using the variable i as a loop
; counter. Note that you are using hexadecimal
; notation for the numbers. You can use decimal,
; octal, or binary as well.
FOR i:=0 TO 127 DO
BEGIN
; For each simulation step, assign the value of
; the loop counter to the input vector using the
; SETF operation. The output of the circuit will
; be simulated using this input, so you can check
; all the possible input cases using
; only a few lines of code.
SETF number := i
END